const Fly = require("../lib/flyio/wx");
const ENV_CONFIG = require("../config/env");
const fly = new Fly(); //创建fly实例

fly.interceptors.request.use((request) => {
    request.timeout = 30000;
    request.headers = { //设置请求头
        "content-type": "application/x-www-form-urlencoded",
        "palt": ENV_CONFIG.palt,
        "version": ENV_CONFIG.version,
        "token": wx.getStorageSync('token')
    }
    // 发送 res.code 到后台换取 openId, sessionKey, unionId
    return request;
})
//配置请求基地址
fly.config.baseURL = ENV_CONFIG.domain + ENV_CONFIG.subDomain
fly.interceptors.response.use(
    (response) => {
        if (response.code === 2000) {
            //跳轉登陸頁
            return;
        }
        wx.hideLoading();
        return response; //请求成功之后将返回值返回
    },
    (err) => {
        //请求出错，根据返回状态码判断出错原因
        console.log(err)
    }
)
export default {
    fly: fly
}